package work.mediway.mdm.biz.event;

import com.mediway.hos.messgateway.model.entity.MessageEntity;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import work.mediway.mdm.biz.dto.biz.PushDataDTO;
import work.mediway.mdm.biz.event.entity.DataPushEvent;
import work.mediway.mdm.biz.event.entity.DictPushEvent;

/**
 * 数据推送
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2021/11/17
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class DataPushEventEventPublisher {

    private final ApplicationEventPublisher applicationEventPublisher;

    /**
     * 广播📢{@link DataPushEvent}事件
     *
     * @param data 数据集合
     */
    public void publishEvent(PushDataDTO data) {
        DataPushEvent event = new DataPushEvent(this);
        event.setData(data);
        applicationEventPublisher.publishEvent(event);
        log.info("broadcast DataPushEvent");
    }

    /**
     * 广播📢{@link DataPushEvent}事件
     *
     * @param messageEntity 消息
     */
    public void publishEvent(MessageEntity messageEntity) {
        DictPushEvent event = new DictPushEvent(this);
        event.setMessageEntity(messageEntity);
        applicationEventPublisher.publishEvent(event);
        log.info("broadcast DataPushEvent");
    }
}
